package com.htgd.gardenexpo.controller;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConCompetitionPrize;
import com.htgd.gardenexpo.entity.GeConCompetitionSports;
import com.htgd.gardenexpo.entity.GeConLeisureSports;
import com.htgd.gardenexpo.page.LeisureSportsQuery;
import com.htgd.gardenexpo.page.PrizeQuery;
import com.htgd.gardenexpo.service.IGeConLeisureSportsService;
import com.htgd.gardenexpo.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 休闲运动 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-27
 */
@RestController
@RequestMapping("/api/leisureSports")
@Api(tags = "休闲运动")
@Slf4j
public class GeConLeisureSportsController {

    @Autowired
    private IGeConLeisureSportsService geConLeisureSportsService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConLeisureSports geConLeisureSports){
        log.info("挑战-添加：{}",geConLeisureSports);
        return geConLeisureSportsService.insert(geConLeisureSports);
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConLeisureSports geConLeisureSports) {
        log.info("挑战-编辑：{}",geConLeisureSports);
        return geConLeisureSportsService.edit(geConLeisureSports);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) throws Exception {
        log.info("挑战-删除：{}",id);
        return geConLeisureSportsService.delete(id);
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConLeisureSportsVO>> list(LeisureSportsQuery leisureSportsQuery) {
        log.info("挑战-列表：{}",leisureSportsQuery);
        PageInfo<GeConLeisureSportsVO> list = geConLeisureSportsService.pageList(leisureSportsQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/details")
    @ApiOperation("详情")
    public CommonResult<GeConLeisureSportsVO> details(String id, HttpServletRequest request) {
        log.info("挑战-详情：{},{}",id,request);
        GeConLeisureSportsVO geConLeisureSportsVO = geConLeisureSportsService.getDetailsById(id,request);
        return CommonResult.success("查询成功",geConLeisureSportsVO);
    }

    @PostMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(@RequestBody GeConLeisureSports geConLeisureSports) {
        return geConLeisureSportsService.review(geConLeisureSports);
    }

    @GetMapping(value = "/getEntryNums")
    @ApiOperation("获取累计报名人数及休闲运动情况")
    public CommonResult<List<LeisureSportsNumsVO>> getEntryNums(@RequestParam(name = "pageNum",required = true,defaultValue = "1")Integer pageNum,
                                                                @RequestParam(name = "pageSize",required = true,defaultValue = "10")Integer pageSize,
                                                                @RequestParam(name = "startTime",required = false)String startTime,
                                                                @RequestParam(name = "endTime",required = false)String endTime,
                                                                @RequestParam(name = "startDate",required = false)String startDate,
                                                                @RequestParam(name = "endDate",required = false)String endDate,
                                                                @RequestParam(name = "type",required = false)String type,
                                                                @RequestParam(name = "orderBy",required = false,defaultValue = "DESC")String orderBy
                                                                    ){
        log.info("综管-获取累计报名人数及休闲运动情况:{},{},{},{},{},{},{},{}",pageNum,pageSize,startTime,endTime,startDate,endDate,type,orderBy);
        return geConLeisureSportsService.getEntryNums(pageNum,pageSize,startTime,endTime,startDate,endDate,type,orderBy);
    }

}
